﻿@model cloudscribe.Core.Web.ViewModels.Account.RegisterViewModel
@using cloudscribe.Core.Web
@using cloudscribe.Core.Web.Components
@using cloudscribe.Core.Models
@using Microsoft.Extensions.Options
@using Microsoft.Extensions.Localization
@using Microsoft.AspNetCore.Authentication
@inject SiteContext Tenant
@inject IStringLocalizer<CloudscribeCore> sr
@inject IOptions<UIOptions> uiOptionsAccessor
@{
    ViewData["BodyClass"] = "account-section registration-page";
    ViewData["SocialFormat"] = sr["Register using your {0} account"];
    ViewData["SocialHeading"] = sr["Use an existing account"];
    var uiOptions = uiOptionsAccessor.Value;
}
@section Meta {
    <meta name="robots" content="noindex" />
}
@section Styles {
    @{await Html.RenderPartialAsync("RegistrationStylePartial"); }
}
@if (!string.IsNullOrWhiteSpace(Model.RecaptchaSiteKey))
{
    <script src='https://www.google.com/recaptcha/api.js'></script>
}
@if (Model.UseInvisibleCaptcha)
{
    <script src="~/cr/js/cloudscribe-register-page.js"></script>
}
<h2>@ViewData["Title"]</h2>
@if (!string.IsNullOrWhiteSpace(Model.RegistrationPreamble))
{
    await Html.RenderPartialAsync("RegisterPreamblePartial", Model);
}
<form id="register-form" asp-controller="Account" asp-action="Register" method="post" asp-route-returnurl='@ViewData["ReturnUrl"]' class="form-horizontal" role="form" data-submit-once="true">
    <input asp-for="UserId" type="hidden" />
    <h4>@sr["Create a new account."]</h4>
    <hr />
    <div asp-validation-summary="All" class="text-danger"></div>
    <div class="form-group">
        <label asp-for="Username" class="col-md-2 control-label">@sr["Username"]</label>
        <div class="col-md-10">
            <div class="input-group">
                <span class="input-group-addon"><i class="@uiOptions.IconUsername" aria-hidden="true"></i></span>
                <input asp-for="Username" class="form-control" />
            </div>
            <span asp-validation-for="Username" class="text-danger"></span>
            @Html.ValidationMessage("usernameerror", new { @class = "text-danger" })
        </div>
    </div>
    <div class="form-group">
        <label asp-for="Email" class="col-md-2 control-label">@sr["Email"]</label>
        <div class="col-md-10">
            <div class="input-group">
                <span class="input-group-addon"><i class="@uiOptions.IconEmail" aria-hidden="true"></i></span>
                <input asp-for="Email" class="form-control" />
            </div>
            <span asp-validation-for="Email" class="text-danger"></span>
        </div>
    </div>
    @{await Html.RenderPartialAsync("RegisterMiddle", Model); }
    <div class="form-group">
        <label asp-for="Password" class="col-md-2 control-label">@sr["Password"]</label>
        <div class="col-md-10">
            <div class="input-group">
                <span class="input-group-addon"><i class="@uiOptions.IconPassword" aria-hidden="true"></i></span>
                <input asp-for="Password" class="form-control" />
            </div>
            <span asp-validation-for="Password" class="text-danger"></span>
        </div>
    </div>
    <div class="form-group">
        <label asp-for="ConfirmPassword" class="col-md-2 control-label">@sr["Confirm Password"]</label>
        <div class="col-md-10">
            <div class="input-group">
                <span class="input-group-addon"><i class="@uiOptions.IconPassword" aria-hidden="true"></i></span>
                <input asp-for="ConfirmPassword" class="form-control" />
            </div>
            <span asp-validation-for="ConfirmPassword" class="text-danger"></span>
        </div>
    </div>
    @if (!string.IsNullOrWhiteSpace(Model.RegistrationAgreement))
    {
        await Html.RenderPartialAsync("RegisterAgreementPartial", Model);
    }
    else
    {
        <input name="AgreeToTerms" value="true" type="hidden" />
    }
    @if (!string.IsNullOrWhiteSpace(Model.RecaptchaSiteKey) && !Model.UseInvisibleCaptcha)
    {
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <div class="g-recaptcha" data-sitekey="@Model.RecaptchaSiteKey"></div>
                @Html.ValidationMessage("recaptchaerror", new { @class = "text-danger" })
            </div>
        </div>
    }

    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            @if (!string.IsNullOrWhiteSpace(Model.RecaptchaSiteKey) && Model.UseInvisibleCaptcha)
            {
                <button class="btn btn-default g-recaptcha" data-sitekey="@Model.RecaptchaSiteKey" data-callback='onCaptchaSubmit' data-enabled-text='@sr["Register"]' data-disabled-text='@sr["Working..."]'>@sr["Register"]</button>
            }
            else
            {
                <button name="submit" type="submit" class="btn btn-default" data-enabled-text='@sr["Register"]' data-disabled-text='@sr["Working..."]'>@sr["Register"]</button>
            }
            @Html.ValidationMessage("registrationError", new { @class = "text-danger" })

        </div>
    </div>
</form>
@{
    var LoginProviders = Model.ExternalAuthenticationList.ToList();
    if (LoginProviders.Count > 0)
    {
        await Html.RenderPartialAsync("SocialLoginPartial", LoginProviders);
    }
}
@section Scripts {
    @{await Html.RenderPartialAsync("RegistrationScriptsPartial"); }
    <script src="~/cr/js/jquery.validate.hooks.min.js"></script>
    <script src="~/cr/js/jqueryvaildation.submitonce-unobtrusive.min.js"></script>
}
